package com.youhome.service.utils;



import com.youhome.service.listhub.Address;
import com.youhome.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chen365 on 2018/05/29.
 */
public class AddressUtils {
    public static String getAddress(Address address) {
        if (address == null) {
            return null;
        }
        List<String> list = new ArrayList<>();

        if (!StringUtils.isEmpty(address.getUnitNumber())) {
            list.add(StringUtils.toUpperCaseIndex(address.getUnitNumber().getValue()));
        }
        if (!StringUtils.isEmpty(address.getFullStreetAddress())) {
            list.add(StringUtils.toUpperCaseIndex(address.getFullStreetAddress()));
        }
        if (!StringUtils.isEmpty(address.getCity())) {
            list.add(StringUtils.toUpperCaseIndex(address.getCity().getValue()));
        }
        if (!StringUtils.isEmpty(address.getStateOrProvince())) {
            list.add(address.getStateOrProvince().getValue());
        }
        if (!StringUtils.isEmpty(address.getPostalCode())) {
            list.add(address.getPostalCode().getValue());
        }
        if (list.size() > 0) {
            return String.join(", ", list);
        } else {
            return null;
        }
    }

    public static String getAddress(String unitNumber, String fullStreetAddress, String city, String state, String zip) {

        List<String> list = new ArrayList<>();

        if (!StringUtils.isEmpty(unitNumber)) {
            list.add(StringUtils.toUpperCaseIndex(unitNumber));
        }
        if (!StringUtils.isEmpty(fullStreetAddress)) {
            list.add(StringUtils.toUpperCaseIndex(fullStreetAddress));
        }
        if (!StringUtils.isEmpty(city)) {
            list.add(StringUtils.toUpperCaseIndex(city));
        }
        if (!StringUtils.isEmpty(state)) {
            list.add(state);
        }
        if (!StringUtils.isEmpty(zip)) {
            list.add(zip);
        }
        if (list.size() > 0) {
            return String.join(", ", list);
        } else {
            return null;
        }
    }
}
